<template>
  <div class="app-container">



    <el-table v-loading="loading" :data="paperList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="序号" align="center" prop="index"/>
      <el-table-column label="试题图片地址" align="center" prop="questionPicture">
        <template v-slot="scope">
          <el-image
            style="width: 100px; height: 100px"
            :src="scope.row.questionPicture"
            fit="contain"
            :preview-src-list="[scope.row.questionPicture]">
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="答案图片地址" align="center" prop="answerPicture">
        <template v-slot="scope">
          <el-image
            style="width: 100px; height: 100px"
            :src="scope.row.answerPicture"
            fit="contain"
            :preview-src-list="[scope.row.answerPicture]">
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == 0">未批阅</el-tag>
          <el-tag v-if="scope.row.status == 1" type="success">已批阅</el-tag>

        </template>
      </el-table-column>
      <el-table-column label="创建者" align="center" prop="createBy"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >进入答疑区
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
import {listPaper, getPaper, delPaper, addPaper, updatePaper} from "@/api/markingPapers";

export default {
  name: "Paper",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 作业试卷表格数据
      paperList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        questionPicture: null,
        answerPicture: null,
        teacherRemarks: null,
        teacherPicture: null,
        studentId: null,
        teacherId: null,
        result: null,
        status: 1,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        questionPicture: [
          {required: true, message: "试题图片地址不能为空", trigger: "blur"}
        ],
        answerPicture: [
          {required: true, message: "答案图片地址不能为空", trigger: "blur"}
        ],
        studentId: [
          {required: true, message: "学生id不能为空", trigger: "blur"}
        ],
        teacherId: [
          {required: true, message: "老师id不能为空", trigger: "blur"}
        ],
        result: [
          {required: true, message: "是否正确不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询作业试卷列表 */
    getList() {
      this.loading = true;
      listPaper(this.queryParams).then(response => {
        response.rows.map((ele,index)=>{
          ele['index']=(this.queryParams.pageNum-1)*this.queryParams.pageSize+index+1
        })
        this.paperList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        jobTestPaperId: null,
        questionPicture: null,
        answerPicture: null,
        teacherRemarks: null,
        teacherPicture: null,
        studentId: null,
        teacherId: null,
        result: null,
        status: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.jobTestPaperId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加作业试卷";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {



      this.$router.push('/markingPapers/Q&Aarea/markingPapers/Q&Aarea/detail?id='+row.jobTestPaperId)

    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/paper/export', {
        ...this.queryParams
      }, `paper_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
